//
//  XLHostSideIncomeDetailsVC.m
//  XiangLove
//
//  Created by 李传坤 on 2018/6/7.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLHostSideIncomeDetailsVC.h"
#import "IMAChatViewController.h"
#import <ReactiveCocoa.h>
#import "XLNavgationViewController.h"
@interface XLHostSideIncomeDetailsVC ()
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headerImage;
@property (weak, nonatomic) IBOutlet UIButton *backbuton;
@property (weak, nonatomic) IBOutlet UIButton *followButton;
@property (weak, nonatomic) IBOutlet UILabel *videoIncome;
@property (weak, nonatomic) IBOutlet UILabel *giftIncome;
@property (weak, nonatomic) IBOutlet UILabel *jingyanNumber;
@property (weak, nonatomic) IBOutlet UILabel *meiliNumber;
@property (weak, nonatomic) IBOutlet UILabel *cardLbl;

@end

@implementation XLHostSideIncomeDetailsVC
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self.navigationController setNavigationBarHidden:YES animated:NO];

}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    [self.navigationController setNavigationBarHidden:NO animated:NO];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    _headerImage.layer.cornerRadius = 55;
    _backbuton.layer.cornerRadius = 5;
    _backbuton.layer.borderWidth = 1;
    _backbuton.layer.borderColor = RGB_HEX(0xFFBB01).CGColor;
    [XLDownloadImageTool downloadImage:_headerImageUrl place:nil imageView:_headerImage];
    [[[XLHTTPSessionManager sharedManager] XLV2GET:@"/api/v2/VideoChat/GetCallResult" parameters:@{@"callId":_callid,@"toUserId":_toUserId,@"userId":[[XLAccountManager shareInstance] model].Id} resultClass:nil]subscribeNext:^(id x) {
        if (x) {
            NSString *minite = [[_timeString componentsSeparatedByString:@":"]objectAtIndex:1];
            NSString *second = [[_timeString componentsSeparatedByString:@":"]lastObject];
            if ([minite integerValue] > 0) {
                _timeLabel.text = [NSString stringWithFormat:@"通话时长:%@分钟%@秒",minite, second];

            }else{
                _timeLabel.text = [NSString stringWithFormat:@"通话时长:%@秒", second];
            }
//            _timeLabel.text = [NSString stringWithFormat:@"%@", x[@"DisplayTime"]];
            _videoIncome.text = [NSString stringWithFormat:@"¥%@",x[@"VideoIncome"]];
            _giftIncome.text = [NSString stringWithFormat:@"¥%@",x[@"GiftIncome"]];
            
            NSString *playCard = K_DEFULT(x[@"DisplayCard"]);
            
            if (playCard.length <= 0) {
                playCard = @"0 视频聊天卡";
            }
            
            NSString *cardNum = [[playCard componentsSeparatedByString:@" "] firstObject];
            
            NSString *cardName = [[playCard componentsSeparatedByString:@" "] lastObject];
            
//            _meiliNumber.text = [NSString stringWithFormat:@"+%@",x[@"Usercp"]];
            _meiliNumber.text = [NSString stringWithFormat:@"+%@",K_DEFULT(cardNum)];
            _cardLbl.text = K_DEFULT(cardName);
            _jingyanNumber.text = [NSString stringWithFormat:@"+%@",x[@"EmpiricalValue"]];
            if ([x[@"IsAttention"] integerValue] == 1) {
                _followButton.hidden = YES;
            }else{
                _followButton.hidden = NO;
            }
        }
    } error:^(NSError *error) {
        
    }];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)followButotn:(id)sender {//关注
    [[[XLHTTPSessionManager sharedManager] XLV2POST:@"/api/v2/UserInfo/Follow" parameters:@{@"FollowId":self.toUserId,@"FansId":[XLAccountManager shareInstance].model.Id} resultClass:nil] subscribeNext:^(id x) {
        self.followButton.hidden = YES;
        [MBProgressHUD showContent:@"关注成功"];
        NSLog(@"关注成功%@",x);
    } error:^(NSError *error) {
        NSLog(@"关注失败%@",error);
        
    }];
}
- (IBAction)backFirstView:(id)sender {//返回
    
    UIViewController * presentingViewController = self.presentingViewController;
    while (presentingViewController.presentingViewController) {
        presentingViewController = presentingViewController.presentingViewController;
    }
    [presentingViewController dismissViewControllerAnimated:YES completion:nil];
    
}
- (IBAction)ChatButton:(id)sender {//私聊
    
    [[TIMFriendshipManager sharedInstance] GetUsersProfile:@[_toUserId] succ:^(NSArray *friends) {
        
        for (TIMUserProfile *pro in friends)
        {
            IMAUser *user = [[IMAUser alloc] initWithUserInfo:pro];
            dispatch_async(dispatch_get_main_queue(), ^{
                IMAChatViewController *chat = [[IMAChatViewController alloc] initWith:user];
                chat.ChatViewBackBlock = ^{
                    UIViewController * presentingViewController = self.presentingViewController;
                    while (presentingViewController.presentingViewController) {
                        presentingViewController = presentingViewController.presentingViewController;
                    }
                    [presentingViewController dismissViewControllerAnimated:NO completion:nil];
                };
                [self.navigationController pushViewController:chat animated:YES];
            });
        }
    } fail:^(int code, NSString *msg) {
        DebugLog(@"vvvFailddd: %d->%@", code, msg);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
